package com.ggymm.browser.core;

import java.lang.reflect.Field;

public class Config {
    public static final String DLL_PATH = "./lib/win64";

    public static void initDll() {
        try {
            Field userPathsField = ClassLoader.class.getDeclaredField("usr_paths");
            userPathsField.setAccessible(true);
            String[] paths = (String[]) userPathsField.get(null);
            StringBuilder sb = new StringBuilder();
            for (String path : paths) {
                if (DLL_PATH.equals(path)) {
                    continue;
                }
                sb.append(path).append(';');
            }
            sb.append(DLL_PATH);
            System.setProperty("java.library.path", sb.toString());
            final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
            sysPathsField.setAccessible(true);
            sysPathsField.set(null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
